package cn.itcast.web.controller.cargo;

import cn.itcast.service.stat.StatService;
import cn.itcast.web.controller.BaseController;
import com.alibaba.dubbo.config.annotation.Reference;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;


@Controller
@RequestMapping("/stat")
public class StatController extends BaseController {

    // 注入dubbo服务接口代理对象（注意导入的包）
    @Reference
    private StatService statService;

    /**
     * 进入统计分析页面
     * http://localhost:8080/stat/toCharts.do?chartsType=factory
     * http://localhost:8080/stat/toCharts.do?chartsType=sell
     * http://localhost:8080/stat/toCharts.do?chartsType=online
     */
    @RequestMapping("/toCharts")
    public String toCharts(String chartsType) { // chartsType = factroy
        return "stat/stat-" + chartsType;
    }

    /**
     * 需求1：统计厂家的销售额
     * @return
     */
    @RequestMapping("/factorySale")
    @ResponseBody
    public List<Map<String, Object>> factorySale(){
        return statService.factorySale();
    }

    /**
     * 需求2：产品销售量要求按前5名统计
     * @return
     */
    @RequestMapping("/productSale")
    @ResponseBody
    public List<Map<String, Object>> productSale(Integer top){
        return statService.productSale(top);
    }

    /**
     * 需求3：按小时统计访问人数
     * @return
     */
    @RequestMapping("/online")
    @ResponseBody
    public List<Map<String, Object>> online(){
        return statService.online();
    }
}